<template>
	<view class="daily">
		<fui-row class="header">
			<fui-col :span="3" :offset="4">
				<fui-button width="48rpx" height="48rpx" background="rgba(0,82,217,0.16)" @click="switchDateBefore">
					<fui-icon name="arrowleft" size="32" color="#0052D9"></fui-icon>
				</fui-button>
			</fui-col>
			<fui-col :span="10" class="fui-flex__center">
				<text class="date">{{date}}</text>
			</fui-col>
			<fui-col :span="3" t-class="align-right">
				<fui-button :disabled="disabledAfter" width="48rpx" height="48rpx" background="rgba(0,82,217,0.16)"
					@click="switchDateAfter">
					<fui-icon name="arrowright" size="32" color="#0052D9"></fui-icon>
				</fui-button>

			</fui-col>
		</fui-row>
		<view class="body">
			<custom-daily-detail-card label="服务台总览">
				<fui-row>
					<fui-col v-for="(item,index) in serviceDeskOverviewConfig" :key="index"
						:span="index ==0 ?'24' :'12'" class="col">
						<view class="grid">
							<view class="grid-left">
								<fui-icon :name="`icon-${item.icon}`" :color="item.iconColor" custom-prefix="iconfont"
									size="48rpx"></fui-icon>
							</view>
							<view class="grid-right">
								<text class="primary" :style="{
									'color':item.valueColor
								}">{{item.value || 0}}</text>
								<text class="label">{{item.label}}</text>
							</view>
						</view>
					</fui-col>
				</fui-row>
			</custom-daily-detail-card>

			<!-- 	<custom-daily-detail-card label="已接电话详情" class="m-t-32"> 
				<view class="box">
					<view class="total">
						<text class="total-user">里斯:<text class="total-num">30</text></text>
						<text class="total-user">里斯:<text class="total-num">30</text></text>
						<text class="total-user">里斯:<text class="total-num">30</text></text>
					</view>
					<fui-row class="seat">
						<fui-col :span="12">
							<text class="seat-who">坐席人员:<text class="seat-user">遮阳伞</text></text>
						</fui-col>
						<fui-col :span="12" class="align-right">
							<text class="seat-time"> 2023-12-12 12:00:00 </text>
						</fui-col>
					</fui-row>
					<fui-row class="dept">
						<fui-col :span="24">
							<text class="dept-addr">报修科室:休息休息/适时适度</text>
						</fui-col>
					</fui-row>
					<fui-row class="report">
						<fui-col :span="20">
							<text class="report-user"> 报修人:张三 </text>
						</fui-col>
						<fui-col :span="4" class="align-right">
							<text class="state">成功</text>
						</fui-col>
					</fui-row>
				</view>
			</custom-daily-detail-card> -->
		</view>
	</view>

</template>

<script>
	import dayjs from 'dayjs'
	import {
		HomeApi
	} from '../../api/home'
	const dateFormat = 'YYYY-MM-DD'

	export default {
		data() {
			return {
				date: '',
				disabledAfter: true,
				serviceDeskOverviewConfig: [{
						icon: 'kefu',
						iconColor: '#000000',
						value: '',
						valueColor: '#000000',
						label: '当日坐席人员',
						type: '',
					},
					{
						icon: 'dianhua',
						iconColor: '#2BA471',
						value: '',
						valueColor: '#2BA471',
						label: '已接电话',
						type: 2,
					},
					{
						icon: 'weijiedianhua',
						iconColor: '#D54941',
						value: '',
						valueColor: '#D54941',
						label: '未接电话',
						type: 1,
					},
					{
						icon: 'yijiangongdan',
						iconColor: '#0052D9',
						value: '',
						valueColor: '#0052D9',
						label: '已建工单',
						type: 4,
					},
					{
						icon: 'yijiejue-01',
						iconColor: '#D8A100',
						value: '',
						valueColor: '#D8A100',
						label: '服务台解决',
						type: null,
					},
					{
						icon: 'jinjilianxiren',
						iconColor: '#8E56DD',
						value: '',
						valueColor: '#8E56DD',
						label: '电话找人',
						type: 7,
					},
					{
						icon: 'wuxiaodianhua',
						iconColor: 'rgba(0,0,0,0.6)',
						value: '',
						valueColor: 'rgba(0,0,0,0.6)',
						label: '无效电话',
						type: 9,
					},
					{
						icon: 'weijiangongdan',
						iconColor: '#E37318',
						value: '',
						valueColor: '#E37318',
						label: '未建工单',
						type: 5,
					},

				]
			}
		},
		onLoad() {
			this.date = dayjs().format(dateFormat)
			this.init()
		},
		methods: {
			async init() {
				const res = await HomeApi.dailyDetail(this.date)
				const l = res.data?.orderCount || []
				for (let i of l) {
					for (let y of this.serviceDeskOverviewConfig) {
						if (i.type === y.type) {
							y.value = i.count
						} else {
							y.value = 0
						}
					}
				}
			},
			// 之前
			switchDateBefore() {
				const _date = dayjs(this.date).subtract(1, 'day').format(dateFormat)
				this.date = _date
				this.disabledAfter = dayjs().isSame(_date, 'day')

				this.init()
			},
			// 之后
			switchDateAfter() {
				const _date = dayjs(this.date).add(1, 'day').format(dateFormat)
				this.date = _date
				this.disabledAfter = dayjs().isSame(_date, 'day')
				this.init()
			},

		}
	}
</script>

<style lang="scss" scoped>
	.daily {
		display: flex;
		flex-direction: column;
		height: 100vh;
		background-color: #f0f2f5;

		.header {
			padding: 32rpx 0;
			background-color: #fff;

			.date {
				font-size: 32rpx;
				font-weight: 600;
				color: rgba(0, 0, 0, 0.9);
				margin-top: 6rpx;
			}
		}

		.body {
			flex: 1;
			overflow: auto;
			padding: 32rpx;
		}
	}

	.switch {
		&-date {}
	}

	.col {
		&+& {
			margin-top: 52rpx;
		}
	}

	.box {
		border-bottom: 1rpx solid #e7e7e7;
	}

	.total {
		padding: 10rpx 0;
		border-bottom: 1px solid #e7e7e7;

		&-user {
			font-size: 28rpx;
			font-weight: 400;
			color: rgba(0, 0, 0, 0.4);

			&+& {
				margin-left: 16rpx;
			}
		}

		&-num {
			font-size: 28rpx;
			font-weight: 400;
			color: rgba(0, 0, 0, 0.9);
			margin-left: 8rpx;
		}
	}

	.seat {
		padding: 10rpx 0;

		&-who {
			font-size: 28rpx;
			font-weight: 400;
			color: rgba(0, 0, 0, 0.9);
		}

		&-user {}

		&-time {
			font-size: 28rpx;
			font-weight: 400;
			color: rgba(0, 0, 0, 0.6);
		}
	}

	.dept {
		padding: 10rpx 0;

		&-addr {
			font-size: 28rpx;
			font-weight: 400;
			color: rgba(0, 0, 0, 0.6);
		}
	}

	.report {
		padding: 10rpx 0;

		&-user {
			font-size: 28rpx;
			font-weight: 400;
			color: rgba(0, 0, 0, 0.6);
		}

		.state {
			font-size: 28rpx;
			font-weight: 400;
			color: #2ba471;
		}
	}

	.grid {
		display: flex;
		flex-direction: row;

		&-left {
			padding: 16rpx;
			background: #f3f3f3;
			border-radius: 12rpx 12rpx 12rpx 12rpx;
			opacity: 1;
		}

		&-right {
			display: flex;
			flex-direction: column;

			margin-left: 12rpx;

			.primary {
				font-size: 28rpx;
				font-weight: 600;
			}

			.label {
				font-size: 24rpx;
				font-weight: 400;
				color: rgba(0, 0, 0, 0.4);
			}
		}
	}
</style>